package com.alks.function.controller.finance.mtlcosts;

import com.alks.common.aop.ApiRestController;
import com.alks.common.aop.WebLogger;
import com.alks.entity.data.response.ResponseInfo;
import com.alks.function.data.dto.finance.mtlcosts.SupCfmPrintDto;
import com.alks.function.data.request.finance.mtlcosts.FinSuppHeadRequest;
import com.alks.function.service.finance.mtlcosts.IPcSuppCfmService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author MS
 * @since 2024/6/14上午9:48
 */
@RestController
@ApiRestController("/mtlCosts")
@Api(value = "财务部", tags = "财务部-材料费用-补单核算作业")
@Slf4j
public class PcSuppCfmController {
    @Autowired
    private IPcSuppCfmService service;

    @WebLogger
    @PostMapping("/suppHeadQuery")
    @ApiOperation(value = "补料单资料查询", tags = "财务部-材料费用-补单核算作业")
    public ResponseInfo suppHeadQuery(@RequestBody FinSuppHeadRequest request) {
        return service.suppHeadQuery(request);
    }

    @WebLogger
    @PostMapping("/suppDetQuery")
    @ApiOperation(value = "补料明细查询", tags = "财务部-材料费用-补单核算作业")
    public ResponseInfo suppDetQuery(@RequestParam@ApiParam(required = true,value = "补料单号") String slipNo) {
        return service.suppDetQuery(slipNo);
    }

    @WebLogger
    @PostMapping("/fitSubQuery")
    @ApiOperation(value = "贴合子材料查询", tags = "财务部-材料费用-补单核算作业")
    public ResponseInfo fitSubQuery(@RequestParam@ApiParam(required = true,value = "材料ID") String mtlNo) {
        return service.fitSubQuery(mtlNo);
    }

    @WebLogger
    @PostMapping("/suppCostComp")
    @ApiOperation(value = "取单价,费用计算", tags = "财务部-材料费用-补单核算作业")
    public ResponseInfo suppCostComp(@RequestParam@ApiParam(required = true,value = "补料单号") String slipNo,
                                     @RequestParam@ApiParam(required = true,value = "1.取材料单价 2.计算责任金额 3.计算人工费用") Integer type,
                                     @RequestParam(required = false)@ApiParam(value = "起始节点【仓储，冲裁，手工，外发，针车，成型】") String dept) {
        return service.suppCostComp(slipNo,type,dept);
    }

    @WebLogger
    @PostMapping("/suppFinalCheck")
    @ApiOperation(value = "补单检核", tags = "财务部-材料费用-补单核算作业")
    public ResponseInfo suppFinalCheck(@RequestParam@ApiParam(required = true,value = "补料单号") List<String> slipNos,
                                       @RequestParam@ApiParam(required = true,value = "0.取消检核 1.检核") Integer type) {
        return service.suppFinalCheck(slipNos,type);
    }

    @WebLogger
    @PutMapping("/suppPriceUpdate")
    @ApiOperation(value = "补料明细单价修改", tags = "财务部-材料费用-补单核算作业")
    public ResponseInfo suppPriceUpdate(@RequestParam@ApiParam(required = true,value = "补料单号") String slipNo,
                                        @RequestParam@ApiParam(required = true,value = "物料ID（如果需要填充单价就传 填充单价 ）") String mtlNo,
                                        @RequestParam(required = false)@ApiParam(value = "金额（如果需要填充单价就传第一排的金额）") BigDecimal price) {
        return service.suppDetPriceUpdate(slipNo,mtlNo,price);
    }

    @WebLogger
    @PostMapping("/suppDutyPriceUpdate")
    @ApiOperation(value = "责任归属汇总免扣金额修改", tags = "财务部-材料费用-补单核算作业")
    public ResponseInfo suppDutyPriceUpdate(@RequestParam@ApiParam(required = true,value = "补料单号") String slipNo,
                                            @RequestParam@ApiParam(required = true,value = "责任归属") String dutyName,
                                            @RequestParam(required = false)@ApiParam("免扣金额") BigDecimal freeAmt) {
        return service.suppDutyPriceUpdate(slipNo,dutyName,freeAmt);
    }

    @WebLogger
    @PutMapping("/suppRekUpdate")
    @ApiOperation(value = "补单备注修改", tags = "财务部-材料费用-补单核算作业")
    public ResponseInfo suppRekUpdate(@RequestParam@ApiParam(required = true,value = "补料单号") String slipNo,
                                        @RequestParam(required = false)@ApiParam(value = "财务备注") String cwRek) {
        service.suppRekUpdate(slipNo,cwRek);
        return ResponseInfo.ok();
    }

    @WebLogger
    @GetMapping("/print/cfm")
    @ApiOperation(value = "打印核算单", tags = "财务部-材料费用-补单核算作业")
    public ResponseInfo cfmPrint(@RequestParam@ApiParam(required = true,value = "补料单号") String slipNo,
                                 @RequestParam@ApiParam(required = true,value = "补料单号") String lotNo) {
        SupCfmPrintDto printList = service.cfmPrint(slipNo,lotNo);
        return ResponseInfo.ok(printList);
    }


}